import Base from '../../base'
import view from '../../views/login/serverList.json'

export default class ServerList extends Base {

	constructor(scene) {
		let groupBtn = {
			type: 'sprite',
			x: -200,
			y: -110,
			url: 'login/btn1.png',
			style: {
				active: 'login/btn2.png',
				hover: 'login/btn2.png'
			},
			event: {
				click: 'selectGroup'
			},
			value: {
				id: 0
			},
			children: {
				btnText: {
					type: 'text',
					x: -45,
					y: -12,
					text: '1-10区',
					style: {
						fontSize : '24px',
						stroke : '#000000',
						strokeThickness: 3
					}
				}
			}
		}
		view.serverList.children = {groupBtn: groupBtn}
		let x = -15, y = -160
		for (let n = 0; n < 3; n++) {
			if(n%2 == 0){
				y += 50
				x = -15
			}else{
				x = 175
			}
			let serverBtn = {
				type: 'sprite',
				x: x,
				y: y,
				url :'login/btn2.png',
				event:{
					click: 'enterServer'
				},
				value: {
					id: n
				},
				children: [
					{
						type: 'text',
						x: -40,
						y: -12,
						text: 'D8传奇',
						style: {
							fontSize :'24px',
							stroke :'#000000',
							strokeThickness: 3
						}
					}
				]
			}
			view.serverList.children[serverBtn+n] = serverBtn
		}
		super(scene, view)
	}

	enterServer(obj){
		this.hide()
		this.scene.loginModule.playDoor()
	}

	selectGroup(obj){
		console.log(obj)
	}

}